import javax.swing.*;
import java.awt.FlowLayout;

// 商品信息查询窗口类
public class QueryBookFrame extends JFrame {

    private JLabel l_name, l_category;
    private JTextField t_name;
    private JButton b_query;
    private JTable table_book;
    private JComboBox<String> c_category;
    private User u = new User("u0001", "张三", "12345", '男',"太原");

    public QueryBookFrame() {
        initFrame();
        initComponents();
        setupLayout();
    }

    private void initFrame() {
        // 窗体初始化
        setTitle("商品信息查询");
        setSize(600, 400);
        setLocation(350, 150);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private void initComponents() {
        l_name = new JLabel();
        l_category = new JLabel();
        t_name = new JTextField();
        b_query = new JButton();
        c_category = new JComboBox<>();
    }

    private void setupLayout() {
        setLayout(new FlowLayout());

        // 书籍信息
        Object[] title = {"编号", "书名", "作者", "定价", "库存"};
        Book[] books = BookDataSet.getBooks();
        Object[][] bookList = new String[books.length][5];
        for (int i = 0; i < books.length; i++) {
            bookList[i][0] = books[i].getId();
            bookList[i][1] = books[i].getName();
            bookList[i][2] = books[i].getAuthor();
            bookList[i][3] = String.valueOf(books[i].getPrice());
            bookList[i][4] = String.valueOf(books[i].getNumber());
        }

        table_book = new JTable(bookList, title);
        JScrollPane pane = new JScrollPane(table_book);
        add(pane);
    }
}
